/*
Java board game library.
Copyright (C) 2011  Deepesh Garg

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package lib ;


public abstract class Board<CellType, MoveType> {
	protected Object boardState [][] ;
	public static void main (String argv[]) {
		
	}

	public Board (int row, int col) {
		boardState = new Object[row][col] ;
	}

	public CellType getCellState (int row, int col) {
		return (CellType) boardState [row][col] ;
	}	
	
	public CellType getCellState (Cell cell) {
		return getCellState (cell.getRow(), cell.getCol()) ;
	}

	public void setCellState (int row, int col, CellType state) {
		boardState [row][col] = state ;
	}

	public void setCellState (Cell cell, CellType state) {
		setCellState(cell.getRow(), cell.getCol(), state) ;
	}
	
	public Board<CellType, MoveType> move (MoveType moveType) {
		return this;
	}
	
	public int getRowCount() {
		return boardState.length ;
	}

	public int getColCount() {
		return boardState[0].length ;
	}
	
	public boolean isValidCellBoard(Cell cell) {
		return cell.getCol() >= 0 && cell.getCol() < getColCount() 
			&& cell.getRow() >=0 && cell.getRow() < getRowCount();
	}
	
	//Close this board state to passed board
	public Board<CellType, MoveType> cloneState (Board<CellType, MoveType> b) {
		if (getColCount() == b.getColCount() && getRowCount() == b.getRowCount()) {
			for (int row = 0; row < getRowCount(); row++) {
				for (int col = 0; col < getColCount(); col++) {
					b.setCellState(row, col, getCellState(row, col));
				}
			}
		}
		return b;
	}
	
	abstract public Board<CellType, MoveType> clone () ; 
}
